<script lang="ts" setup>
import { PropType } from 'vue'
import { formatNumber } from '@/utils/format'
import { toPage } from '@/hook/routeTopage'
import { playlistType } from '@/store/modules/types'

defineProps({
  playlist: {
    type: Object as PropType<playlistType[]>,
    required: true
  },
  iconCenter: {
    type: Boolean,
    default: () => false
  }
})
const toPlaylist = (item: playlistType) => {
  toPage('playlist', { id: item.id })
}
</script>

<template>
  <div class="flex_container">
    <template v-for="item in playlist" :key="item.id">
      <div class="recommend_box">
        <div class="recommend_image" @click="toPlaylist(item)">
          <img
            :class="item.name === '每日歌曲推荐' ? 'daily_song' : ''"
            v-lazy="item.coverImgUrl ?? item.picUrl"
          />
          <div
            class="shadow"
            :style="{
              'background-image': `url(${item.coverImgUrl ?? item.picUrl})`
            }"
          ></div>
          <i class="recommend_play" :class="{ center: iconCenter }">
            <i class="icon-24gf-play"></i>
          </i>
          <i v-if="item.creator" class="nickname icon-yonghu">
            {{ item.creator?.nickname }}
          </i>
          <i v-if="item.name !== '每日歌曲推荐'" class="icon-24gl-play">
            {{
              item.playCount
                ? formatNumber(item.playCount)
                : formatNumber(item.playcount)
            }}
          </i>
          <i v-if="item.name === '每日歌曲推荐'" class="icon-rili2"> </i>
          <i v-if="item.name === '每日歌曲推荐'" class="icon_date">{{
            new Date().getDate()
          }}</i>
        </div>
        <p class="recommend_tip" @click="toPlaylist(item)">{{ item.name }}</p>
      </div>
    </template>
  </div>
</template>

<style scoped lang="scss">
.flex_container {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
}

.recommend_box {
  width: 18%;
  height: auto;
  margin-bottom: 20px;
  margin-right: 2.5%;
  position: relative;
  &:nth-child(5n) {
    margin-right: 0;
  }
  p {
    margin-top: 12px;
    font-size: 16px;
    cursor: pointer;
    color: var(--music-link-color);
    &:hover {
      color: var(--music-link-hover-color);
    }
  }
  .daily_song {
    transform: scale(1.2);
    filter: blur(6px);
  }
}
.recommend_image {
  position: relative;
  width: 100%;
  min-height: 190px;
  border-radius: 6px;
  cursor: pointer;
  overflow: hidden;
  transition: all 0.4s;
  &:hover {
    box-shadow: 0px 15px 15px -3px rgba(107, 107, 107, 0.3);
    .recommend_play {
      opacity: 1;
    }
  }
  .icon-rili2 {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 72px;
    color: #f1f1f1;
  }
  .icon_date {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-40%, -24%);
    font-weight: bold;
    font-size: 32px;
    font-weight: bold;
    color: #f1f1f1;
  }
  .icon-24gl-play {
    position: absolute;
    top: 7px;
    right: 7px;
    font-size: 14px;
    color: #f1f1f1;
  }
  .recommend_play {
    bottom: 10px;
    right: 10px;
  }
  .center {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 48px;
    height: 48px;
    background-color: rgb(228, 227, 227, 0.7);
  }
  .nickname {
    position: absolute;
    bottom: 12px;
    left: 12px;
    font-size: 14px;
    color: #f1f1f1;
  }
}

.shadow {
  position: absolute;
  top: 12px;
  height: 100%;
  width: 100%;
  filter: blur(16px) opacity(0.6);
  transform: scale(0.92, 0.96);
  z-index: -1;
  background-size: cover;
  border-radius: 0.75em;
  aspect-ratio: 1/1;
}
</style>
